/**
 * Created by joustany on 17/11/18.
 */
$(function () {
    getShowView()
})
console.log(document.referrer)
function getShowView() {
    var params = JSON.parse(window.localStorage.user);
    var redirect = JSON.parse(decodeURIComponent(params['redirect']));
    $.ajax({
        url: configApi('/user/my'),
        data: {
            access_token:redirect.token
        },
        dataType: 'json',
        cache:false,
        ifModified :true ,
    }).done(function (res) {
        console.log(res)
        if (res.success){
            showView(res.data)
        }else {
            layer.open({
                content: res.message
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        }
    }).fail(function () {
        layer.open({
            content: "服务器异常,请退出重试"
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
        });
    })
}
function showView(user) {
    "use strict"
    // console.log(window.localStorage.users)
    if(location.search){
        var users = $.urlGet()
        $('.packet—succe-container').show()
        $('.succe_num').text(users.money)
        $('.succe_xin').text(users.title)
    }else {
        $('.packet—succe-container').hide()
    }
    $('.head_portrait img').attr('src',user.avatar)
    $('.head_name').html(user.name)
    $('.head_phone').html(user.phone)
    $('.wallet_right').html(user.service_phone)
    $('.head_balance .price').html(user.balance)
    $('.call').attr('href','tel:'+ user.service_phone +'')
}
$(document).on('click','.welfare',function () {
    window.location.href = './welfare.html'
})
$(document).on('click','.order',function () {
    window.location.href = './orderList.html'
})
$(document).on('click','.succe_close',function () {
    window.localStorage.removeItem('users')
    $('.packet—succe-container').hide()
})
$(document).on('click','.head_balance .gift',function () {
    _hmt.push(["_trackEvent", "充值", "我的-充值"]);
    setTimeout(function () {
        window.location.href = './topUp.html'
    },200)
})
// pushHistory();
// window.addEventListener("popstate", function(e) {
//     window.location.href = './index.html'
//     params.removeItem('packet')
// }, false);
// function pushHistory() {
//     var state = {
//         title: "title",
//         url: "#"
//     };
//     window.history.pushState(state, "title", "");
// }
